//==================================================================
//  Copyright (C) 2006  Davide Pasca
//
//  This library is free software; you can redistribute it and/or
//  modify it under the terms of the GNU Lesser General Public
//  License as published by the Free Software Foundation; either
//  version 2.1 of the License, or (at your option) any later version.
//
//  This library is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
//  Lesser General Public License for more details.
//
//  You should have received a copy of the GNU Lesser General Public
//  License along with this library; if not, write to the Free Software
//  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
//==================================================================
/// @file
///
///
/// 
/// @author Davide Pasca
/// 
//==================================================================

#ifndef RENDM5D_PNTSPRT_H
#define RENDM5D_PNTSPRT_H

#include "psys.h"
#include "m5d_mesh.h"
#include "rend_base.h"

//==================================================================
namespace RendM5D {

//==================================================================
//
//==================================================================
class PntSprt
{
	RendDevice							*_rdevicep;
	static const int					NUM_PARTICLE_BUFFERS = 3;

	autodel<RendVertexBuffer>	_vbuffs[NUM_PARTICLE_BUFFERS];
	int									_cur_buff_idx;

	bool								_need_update[NUM_PARTICLE_BUFFERS];
	PMath::Matrix44						_view_obj_m;

public:
	PSYS::sync_ptr<M5D::PntSprt>		_mpntsprtp;

	//--------------------------------------------------------------
	PntSprt( M5D::PntSprt *mpntsprtp, RendDevice *rdevicep );
	~PntSprt();

	static void		BeginRenderState_s( RendDevice *rdevicep );
	static void		EndRenderState_s( RendDevice *rdevicep );

	void			PreRender();
	void			Render();

private:
	void		updateGeometry( int buff_idx );
	static void onSuperModify_s( void *mythis ){ ((RendM5D::PntSprt *)mythis)->onSuperModify(); }
	void		onSuperModify()
	{
		for (int i=0; i < NUM_PARTICLE_BUFFERS; ++i)
			_need_update[i] = true;
	}

	friend class Scene;
};

};

#endif
